<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('意见反馈列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <p>应用：</p>
                                <select name="app" th:with="type=${@dict.getType('storage_app_type')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>：</label>
                                <select name="status" th:with="type=${@dict.getType('feedback_status')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="common:feedback:export">
                    <i class="fa fa-download"></i> 导出
                 </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('common:feedback:edit')}]];
        var removeFlag = [[${@permission.hasPermi('common:feedback:remove')}]];
        var appDatas = [[${@dict.getType('storage_app_type')}]];
        var statusDatas = [[${@dict.getType('feedback_status')}]];
        var prefix = ctx + "common/feedback";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "意见反馈",
                sortName: "id",
     		    sortOrder: "desc",
                columns: [{
                    checkbox: true
                },
                {
                    field : 'id', 
                    title : 'id',
                    visible: false
                },
                {
                    field : 'app',
                    title : '应用',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(appDatas, value);
                    }
                },
                {
                    field : 'type',
                    title : '反馈类型'
                },
                {
                    field : 'content', 
                    title : '内容',
                    formatter: function(value, row, index) {
                		return $.table.tooltip(value, 80);
                	}
                },
                {
                    field : 'contact', 
                    title : '联系方式'
                },
                {
                    field : 'url', 
                    title : '图片',
                    formatter: function(value, row, index) {
                       if(value){
                           return `<a href='${value}' target='_blank'><img src='${value}' width=70 height=94 /></a>`
                       }
                    }
                },
                {
                    field : 'kkid',
                    title : 'kkid'
                },
                {
                    field : 'kkNumber',
                    title : 'k号'
                },
                {
                    field : 'ua',
                    title : 'ua',
                    visible: false
                },
                {
                    field : 'createdTime', 
                    title : '反馈时间'
                },
                {
                    field: 'status',
                    title: '处理状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(statusDatas, value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        //actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        if(row.status == 0){
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="updateStatus(\'' + row.id + '\', 1)"><i class="fa fa-approve"></i>标记已处理</a> ');
                        }else if(row.status == 1){
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="updateStatus(\'' + row.id + '\', 0)"><i class="fa fa-remove"></i>标记未处理</a> ');
                        }
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function updateStatus(id, status){
		   	let msg ;
		   	switch(status){
		   	   case 0:
		   	      msg = "确定要标记为未处理吗？";
		   	      break;
		   	   case 1:
		   	      msg = "确定要标记为已处理吗？";
		   	      break;
		   	}
		    $.modal.confirm(msg, function() {
				$.operate.post(prefix + "/updateStatus/" + id, { "status": status});
		    })
		}

    </script>
</body>
</html>